package com.dao;

import com.utils.JDBCUnits;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class GivePraiseDao {
    /**
     * 点赞，纸条赞数加一
     * @param id
     * @param note_id
     */
    public static void IntoLike(int id , int note_id){
        Connection c = null;
        PreparedStatement ps = null;
        try {
            c = JDBCUnits.getConnectino();
            String sql = "insert into likesystem(user_id,note_id,like_time) values(?,?,now())";
            ps = c.prepareStatement(sql);
            ps.setInt(1,id);
            ps.setInt(2,note_id);
            ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCUnits.close(c,ps);
        }
    }

    /**
     * 取消赞
     * @param id
     * @param note_id
     */
    public static void CancelLike(int id,int note_id){
        Connection c = null;
        PreparedStatement ps = null;
        try {
            c = JDBCUnits.getConnectino();
            String sql = "delete from likesystem where user_id=? and note_id=?";
            ps = c.prepareStatement(sql);
            ps.setInt(1,id);
            ps.setInt(2,note_id);
            ps.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JDBCUnits.close(c,ps);
        }
    }
}
